import 'package:flutter/cupertino.dart';
import 'package:love_app/common/su_dialog.dart';
import 'package:love_app/common/su_dio.dart';
import 'package:love_app/config/path_url.dart';
import 'package:love_app/enum/send_message.dart';
import 'package:love_app/model/response_model.dart';
import 'package:love_app/service/base_api.dart';


class MessgerApi extends BaseApi{
  /// 发送验证码接口
  Future<bool> sendMesage(String phone, SendMessageType type) async {
    Map postData = {
      'phone': phone,
      'type': getMessageType(type),
    };
    String path = PathUrl.basePath('sendMessage');
    ResponseModel model = await SuDio().postRequest(path, data: postData);
    if(isSuccess(model.data) == true){
      SuDialog.showToast(getMessage(model.data));
      return true;
    }
    SuDialog.showToast(getMessage(model.data));
    return false;
  }

  // 获取要发送验证码的类型
  int getMessageType(SendMessageType type){
    int messageType;
    if(type == SendMessageType.register){
      messageType = 1;
    }else if(type == SendMessageType.login){
      messageType = 2;
    }else if(type == SendMessageType.update){
      messageType = 2;
    }
    return messageType;
  }
}
